package com.bw.mylogger;

import com.bw.mylogger.common.LoggerLevel;
import com.bw.mylogger.common.LoggerType;
import com.bw.mylogger.impl.LogcatImpl;

import java.util.logging.Logger;

public class MyLogger implements LoggerInterface{
    private LoggerType type;
    private LoggerLevel level;
    private String tag;
    private boolean isOpen;

    private MyLogger(LoggerType type,LoggerLevel level,String tag,boolean isOpen){
        this.type = type;
        this.level = level;
        this.tag = tag;
        this.isOpen = isOpen;

        switch (type){
            case Logcat:
                iLogger=new LogcatImpl();
                break;
            case Sqlite:
            case Server:
            case Console:
            default:
                iLogger=new LogcatImpl();
                break;
        }
        iLogger.isOpen(this.isOpen);
        iLogger.lowestLevel(this.level);
        iLogger.setTag(this.tag);
    }

    private LoggerInterface iLogger;

    @Override
    public void debug(String tag, String log) {
        this.iLogger.debug(tag,log);
    }

    @Override
    public void info(String tag, String log) {
        this.iLogger.info(tag,log);
    }

    @Override
    public void warning(String tag, String log) {
        this.iLogger.warning(tag,log);
    }

    @Override
    public void error(String tag, String log) {
        this.iLogger.error(tag,log);
    }

    @Override
    public void isOpen(boolean _isOpen) {

    }

    @Override
    public void setTag(String tag) {

    }

    @Override
    public void lowestLevel(LoggerLevel level) {

    }

    public static class Builder{
        private LoggerType type;
        private LoggerLevel lowestLevel;
        private String tag;
        private boolean isOpen;
        public Builder setType(LoggerType _type){
            this.type=_type;
            return this;
        }
        public Builder setLowestLevel(LoggerLevel _level){
            this.lowestLevel=_level;
            return this;
        }
        public Builder setTag(String _tag){
            this.tag=_tag;
            return this;
        }
        public Builder setOpen(boolean _open){
            this.isOpen=_open;
            return this;
        }
        public MyLogger Build(){
            return new MyLogger(type,lowestLevel,tag,isOpen);
        }
    }
}
